package 异常.day2.demo1;

import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        try {
            String password=getPass1();
            System.out.println(password);
        } catch (MyPassExe myPassExe) {
            myPassExe.printStackTrace();
        }
    }
    static String getPass()throws MyPassExe{
        Scanner in=new Scanner(System.in);
        String pass=in.next();
        boolean b=pass.matches(".*[a-z]+.*");
        if(!b){
            throw new MyPassExe("必须包含小写！");
        }
        b=pass.matches(".*[A-Z]+.*");
        if(!b){
            throw new MyPassExe("必须包含大写！");
        }
        if(!pass.matches(".*[0-9]+.*")){
            throw new MyPassExe("必须包含数字！");
        }
        if(pass.length()<6){
            throw new MyPassExe("长度必须大于等于6！");
        }
        return pass;
    }
    static String getPass1()throws MyPassExe{
        Scanner in=new Scanner(System.in);
        String pass=in.next();
        int[]sure={-1,-1,-1,-1};
        //判断密码长度是否合法
        if(pass.length()>=6){
            sure[0]=1;
        }

        //判断大小写和数字
        char tmp;
        for(int i=0;i<pass.length();i++){
            tmp=pass.charAt(i);
            if(tmp>='a'&&tmp<='z'){
                sure[1]=1;
            }

            if(tmp>='A'&&tmp<='Z'){
                sure[2]=1;
            }
            if(tmp>='0'&&tmp<='9'){
                sure[3]=1;
            }
        }

        for(int i:sure){
            if(i!=1){
                throw new MyPassExe("密码必须有大小写和数字，且长度大于6");
            }
        }
        return pass;
    }

}
